package com.gameapplet.question.controller;

import com.gameapplet.challenge.service.Impl.ChallengeTestServiceImpl;
import com.gameapplet.item.model.StageQuestionMapper;
import com.gameapplet.item.service.Impl.ItemServiceImpl;
import com.gameapplet.item.service.Impl.StageQuestionMapperServiceImpl;
import com.gameapplet.question.model.Question;
import com.gameapplet.question.service.Impl.QuestionServiceImpl;

import com.gameapplet.stage.service.Impl.StageServiceImpl;
import com.gameapplet.util.MathRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/question")
public class QuestionController {
    @Resource(name = "questionService")
    QuestionServiceImpl questionService;
    @Resource(name = "stageService")
    StageServiceImpl stageService;
    @Resource(name = "stageQuestionMapperService")
    StageQuestionMapperServiceImpl stageQuestionMapperService;
    @Resource(name = "itemService")
    ItemServiceImpl itemService;

    @RequestMapping("/getquestion/{stagenum}")
    @ResponseBody
    public List<Question> findQuestion(@PathVariable("stagenum") String stagenum) {
        try {
            String stageid = stageService.selectStageidByStagenum(stagenum);
          //  List<StageQuestionMapper> stageQuestionMapperList = stageQuestionMapperService.selectQuestionidByStageid(stageid);
            List<StageQuestionMapper> list=stageQuestionMapperService.selectQuestionid();
            // //所有问题的ID 集合
            List newlist = new ArrayList();
            int length = list.size();
            int[] bool =  MathRandom.MyRandom(10,length);//产生的随机数
              for(int i =0;i<bool.length;i++){
                  newlist.add(list.get(bool[i]));
              }
               System.out.println(newlist);
            List<Question> questionlist = questionService.selectQuestionlistById(newlist);
            if(questionlist.size()<10){
                System.out.println("小于10题");
            }
            System.out.println(questionlist);
            return questionlist;
        }catch (Exception e){
            e.printStackTrace();
        }
        return  null;
    }

}
